//
//  Trade_VC.h
//  KaChing_App
//
//  Created by Jordan Robert Yust on 4/6/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "DataManager.h"


@interface Trade_VC : UIViewController <UISearchBarDelegate, UITextFieldDelegate,
										UIActionSheetDelegate>
{
	DataManager *dataManager;			// The dataManager object (universally distributed throughout app)
	NSNumberFormatter *numberFormatter;	// Used in formatting prices, cash, etc.
	NSNumber *availableCashNumber;	// The available cash as an NSNumber
	NSNumber *stockPrice;		// The stock price as an  NSNumber
	NSNumber *quantityNumber;	// The quantity as an NSNumber
	NSNumber *totalPrice;		// The total price (#stocks * the price of the stock)
	
	NSDictionary *portfolio;	// The user's portfolio
	NSString *stockTicker;		// The stock ticker to be traded
	
	UIActionSheet *action_actionSheet;	// The ActionSheet allowing the user to decide which action the trade is (buy, sell, short sell, buy to cover)
	UIAlertView *tradeSummary_alertView;		// The AlertView verifying the trade criteria before actually performing the trade
	UIAlertView *successfulTrade_alertView;		// The AlertView confirming a successful trade took place
	
	/* IBOutlets */
	IBOutlet UILabel *availableCashLabel_Top;	// The label that displays the available cash at the top of the view
	IBOutlet UILabel *stockPriceLabel;			// The label that displays the stock's price
	IBOutlet UILabel *tradeHeaderLabel;			// The label that serves as the first header in the view
	IBOutlet UILabel *actionTypeLabel;		// The label that displays what action the trade is (buy, sell, short sell, buy to cover)
	IBOutlet UITextField *quantityTextField;	// The textfield that holds the amount of stocks to trade
	IBOutlet UITextField *totalPriceTextField;	// The textfield that holds the total price of the trade (price of stock * #stocks)
	IBOutlet UILabel *smallHeaderLabel;			// The label that serves as the second header (smaller) in the view
	IBOutlet UIButton *tradeButton;				// The button that triggers the trade
}

/* PROPERTIES */

@property(nonatomic, retain) DataManager *dataManager;
@property(nonatomic, retain) NSNumberFormatter *numberFormatter;
@property(nonatomic, retain) NSNumber *availableCashNumber;
@property(nonatomic, retain) NSNumber *stockPrice;
@property(nonatomic, retain) NSNumber *quantityNumber;
@property(nonatomic, retain) NSNumber *totalPrice;

@property(nonatomic, retain) NSDictionary *portfolio;
@property(nonatomic, retain) NSString *stockTicker;

@property(nonatomic, retain) UIActionSheet *action_actionSheet;
@property(nonatomic, retain) UIAlertView *tradeSummary_alertView;
@property(nonatomic, retain) UIAlertView *successfulTrade_alertView;

@property(nonatomic, retain) UILabel *availableCashLabel_Top;
@property(nonatomic, retain) UILabel *tradeHeaderLabel;
@property(nonatomic, retain) UILabel *stockPriceLabel;
@property(nonatomic, retain) UILabel *actionTypeLabel;
@property(nonatomic, retain) UITextField *quantityTextField;
@property(nonatomic, retain) UITextField *totalPriceTextField;
@property(nonatomic, retain) UILabel *smallHeaderLabel;
@property(nonatomic, retain) UIButton *tradeButton;

/* METHODS */
- (void) createFormatters;
- (void) updateTotalPrice;
- (BOOL) checkTradeCriteria_ForAction:(NSString *) actionType;

- (void) getPortfolioInfo;
- (void) getTickerInfo;

- (IBAction) updateTradeCalculations;
- (IBAction) refreshData;
- (IBAction) changeActionType;
- (IBAction) performTrade;

@end